package org.example.school.controller;

import org.example.school.business.StudentHomeworkInfo;
import org.example.school.common.Result;
import org.example.school.entity.AssignmentSubmissions;
import org.example.school.model.dto.AssignmentSubmissionDTO;
import org.example.school.model.dto.StudentAssignmentDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学生作业控制器
 * 处理学生查看作业、提交作业等操作
 */
@RestController
@RequestMapping("/student/homework")
@CrossOrigin
public class StudentHomeworkController {

    @Autowired
    private StudentHomeworkInfo studentHomeworkInfo;

    /**
     * 获取学生作业列表
     * @return 作业列表
     */
    @GetMapping("/list")
    public Result<List<StudentAssignmentDTO>> getHomeworkList(@RequestParam(required = false) String submissionStatus) {
        return studentHomeworkInfo.getHomeworkList(submissionStatus);
    }

    /**
     * 提交作业
     * @param submissionDTO 作业提交信息
     * @return 提交结果
     */
    @PostMapping("/submit")
    public Result<String> submitHomework(@RequestBody AssignmentSubmissionDTO submissionDTO) {
        return studentHomeworkInfo.submitHomework(submissionDTO);
    }

    /**
     * 获取作业提交记录
     * @param assignmentId 作业ID
     * @return 作业提交记录
     */
    @GetMapping("/submission/{assignmentId}")
    public Result<AssignmentSubmissions> getSubmissionByAssignmentId(@PathVariable Long assignmentId) {
        return studentHomeworkInfo.getSubmissionByAssignmentId(assignmentId);
    }
}